package com.wbao.dianniu.update;

import com.wbao.dianniu.data.Childrens;
import com.wbao.dianniu.data.QaResponse;
import com.wbao.dianniu.data.QuestAnswerListData;

import java.util.LinkedList;

/**
 * Created by yejianjun on 2018/6/15.
 */

public class TwoComDataChangeManager {
    private static LinkedList<ITwoComDataChangerListener> mListener;
    private static TwoComDataChangeManager instance;

    public static TwoComDataChangeManager getInstance() {
        if (null == instance) {
            mListener = new LinkedList<ITwoComDataChangerListener>();
            instance = new TwoComDataChangeManager();
        }
        return instance;
    }

    private TwoComDataChangeManager() {
    }

    public interface ITwoComDataChangerListener {

        /**
         * 新增一条数据更新
         *
         * @param id
         * @param childrens
         */
        public void addOneTwoCommentData(int id, Childrens childrens);

        /**
         * 删除更新（By id）
         *
         * @param id
         */
        public void delOneTwoCommentData(int id, int childId);

        /**
         * 点赞数更新
         *
         * @param id
         * @param isGood
         * @param goodCounts
         */
        public void priseCommentNotify(int id, int isGood, int goodCounts);

        /**
         * 回复数更新
         *
         * @param id
         * @param answerCounts
         */
        public void replyCommentNotify(int id, int answerCounts);
    }


    public boolean addCommentChangeListener(ITwoComDataChangerListener listener) {
        if (null != mListener) {
            return mListener.add(listener);
        }
        return false;
    }

    public boolean removeCommentChangeListener(ITwoComDataChangerListener listener) {
        if (null != mListener) {
            return mListener.remove(listener);
        }
        return false;
    }


    public void addOneCommentNotify(int id, Childrens childrens) {
        for (int i = 0; i < mListener.size(); i++) {
            mListener.get(i).addOneTwoCommentData(id, childrens);
        }
    }

    /**
     * 删除数据通知（通过ID）
     *
     * @param id
     */
    public void delOneCommentData(int id, int childId) {
        for (int i = 0; i < mListener.size(); i++) {
            mListener.get(i).delOneTwoCommentData(id, childId);
        }
    }

    /**
     * 点赞数改变通知
     */
    public void priseCommentNotify(int id, int isGood, int goodCounts) {
        for (int i = 0; i < mListener.size(); i++) {
            mListener.get(i).priseCommentNotify(id, isGood, goodCounts);
        }
    }

    /**
     * 回复数改变通知
     */
    public void replyCommentNotify(int id, int answerCounts) {
        for (int i = 0; i < mListener.size(); i++) {
            mListener.get(i).replyCommentNotify(id, answerCounts);
        }
    }

}
